package org.Help_Desk.Entity;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import org.Help_Desk.Model.DBConnection;

public class Employee {
	private int employeeid;
	private String fname;
        private String lname;
	
	private String address;
	private String contactnumber;
	private String emailid;
	private String dob;
	
	public int getEmployeeid() {
		return employeeid;
	}
	public void setEmployeeid(int employeeid) {
		this.employeeid = employeeid;
	}
	
	public String getFname() {
		return fname;
	}
	public void setFname(String fname) {
		this.fname = fname;
	}
        public String getLname() {
		return lname;
	}
	public void setLname(String lname) {
		this.lname = lname;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getContactNumber() {
		return contactnumber;
	}
	public void setContactNumber(String contactnumber) {
		this.contactnumber = contactnumber;
	}
	public String getEmailId() {
		return emailid;
	}
	public void setEmailId(String emailid) {
		this.emailid = emailid;
	}
	public String getDOB() {
		return dob;
	}
	public void setDOB(String dob) {
		this.dob = dob;
	}
        public void fetchemployee(int sessionid) throws SQLException
	{
		try
                {
                    DBConnection dbConn = new DBConnection();
                    dbConn.connect();
		
		ResultSet rs = dbConn.customQuery("SELECT Emp_Id,Emp_Fname,Emp_Lname,Emp_Address,Emp_Contact_No,Emp_Email,DOB from employee where Emp_Id='" + sessionid +"' ");
		while( rs.next() ) { 
		setAddress(rs.getString("Emp_Address"));
		setEmailId(rs.getString("Emp_Email"));
		setContactNumber(rs.getString("Emp_Contact_No"));
		
		setFname(rs.getString("Emp_Fname"));
                setLname(rs.getString("Emp_Lname"));
		setDOB(rs.getString("DOB"));
		setEmployeeid(Integer.parseInt(rs.getString("Emp_Id")));
		System.out.println(rs.getString("Emp_Email"));
		}
		}
		catch(Exception e)
		{
		}
	}
        public void UpdateEmployee() throws SQLException
	{
		System.out.println("hereup");
		String DOB=getDOB();
		String num=getContactNumber();
		String add=getAddress();
		int id=getEmployeeid();
                DBConnection dbConn = new DBConnection();
                dbConn.connect();
                String s="UPDATE Employee set DOB='"+ DOB +"',Emp_Contact_No='"+ num +"',Emp_Address='"+ add +"' where Emp_Id='"+ id +"'";
                dbConn.executeQuery(s);
                dbConn.disconnect();
                
		
	}
        public List<Complain> fetchComplain() throws SQLException
        {
            List<Complain> ls=new ArrayList<Complain>();
                try
                {
                    DBConnection dbConn = new DBConnection();
                    dbConn.connect();
                
		ResultSet rs = dbConn.customQuery("SELECT Comp_id,Cust_Id,Comp_Desc,Start_Date,Comp_Title from complain_list where Priority_Id IS NULL ");
                System.out.println("comp");
		while( rs.next() ) { 
                Complain com=new Complain();
		com.setCompid(Integer.parseInt(rs.getString("Comp_Id")));
		com.setDesc(rs.getString("Comp_Desc"));
                //SimpleDateFormat dateTest = new SimpleDateFormat("dd/mm/yy"); 
		com.setStartDate(rs.getString("Start_Date"));
		com.setTitle(rs.getString("Comp_Title"));
		com.setCustid(rs.getString("Cust_Id"));
                ls.add(com);
                System.out.println(com.getCustid());
		}
                
		}
		catch(Exception e)
		{
		}
                return ls;
    }
        public List<String> fetchPriority() throws SQLException
        {
            List<String> ls=new ArrayList<String>();
                try
                {
                    DBConnection dbConn = new DBConnection();
                    dbConn.connect();
                
		ResultSet rs = dbConn.customQuery("SELECT Priority_Desc from priority");
		while( rs.next() ) {
                ls.add(rs.getString("priority_Desc"));
		}
                
		}
		catch(Exception e)
		{
		}
                return ls;
        }
        public List<String>fetchCategory() throws SQLException
        {
            List<String> ls=new ArrayList<String>();
                try
                {
                    DBConnection dbConn = new DBConnection();
                    dbConn.connect();
                
		ResultSet rs = dbConn.customQuery("SELECT Cat_Desc from category");
		while( rs.next() ) {
                ls.add(rs.getString("Cat_Desc"));
		}
                
		}
		catch(Exception e)
		{
		}
                return ls;
        }
        public List<Complain> fetchComplain(String compid) throws SQLException
        {
            List<Complain> ls=new ArrayList<Complain>();
                try
                {
                    DBConnection dbConn = new DBConnection();
                    dbConn.connect();
                
		ResultSet rs = dbConn.customQuery("SELECT Comp_Id,Comp_Desc,Comp_Title from complain_list where Comp_Id='"+ compid +"' ");
                
		while( rs.next() ) { 
                Complain com=new Complain();
		com.setCompid(Integer.parseInt(rs.getString("Comp_Id")));
		com.setDesc(rs.getString("Comp_Desc"));
                //SimpleDateFormat dateTest = new SimpleDateFormat("dd/mm/yy"); 
		
		com.setTitle(rs.getString("Comp_Title"));
		
                ls.add(com);
                System.out.println(com.getCompid());
                System.out.println("desc");
		}
                
		}
		catch(Exception e)
		{
		}
                return ls;
    }
}


